package com.team.easybuy.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.team.easybuy.entity.Car;
import com.team.easybuy.entity.Product;
import com.team.easybuy.service.ProductService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/pro")
public class ProController {

    @Resource
    private ProductService productService;

    @RequestMapping("/PageByAllPro")
    public PageInfo<Product> PageByAllPro(@RequestParam Map<String, Object> params) {
        return productService.solrByName(params);
    }

    @RequestMapping("/addPro")
    public boolean addPro(Product product, @RequestParam("file") MultipartFile file) {
        return productService.addPro(product, file);
    }

    @RequestMapping("/delete/{id}")
    public boolean deletePro(@PathVariable Integer id) {
        return productService.delPro(id);
    }

    @RequestMapping("/loadPro/{id}")
    public Product loadPro(@PathVariable Integer id) {
        return productService.selectById(id);
    }

    @RequestMapping("/editProNoFile")
    public boolean editProNoFile(@RequestBody Product product) {
        return productService.editProNoFile(product);
    }

    @RequestMapping("/editProHasFile")
    public boolean editProHasFile(Product product, @RequestParam("file") MultipartFile file) {
        return productService.editProHasFile(product, file);
    }

    @RequestMapping("/checkNum")
    public boolean checkNum(@RequestBody List<Car> carList) {
        return productService.checkNum(carList);
    }
}
